package com.test.sshshiro.framework;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;

import com.test.sshshiro.framework.page.BaseQuery;
import com.test.sshshiro.framework.page.Page;

@Transactional
public abstract class BaseServiceImpl<E, PK extends Serializable> implements BaseService<E, PK> {


	@Override
	@Transactional(readOnly = true)
	public E getById(PK id) throws DataAccessException {
		return (E) getEntityDAO().getById(id);
	}

	@Override
	@Transactional(readOnly = true)
	public List<E> findAll() throws DataAccessException {
		return getEntityDAO().findAll();
	}
	
	@Override
	@Transactional(readOnly = true)
	public List<E> findByProperty(String[] property, Object[] value) throws DataAccessException {
		return getEntityDAO().findAllBy(property, value);
	}
	
	@Override
	@Transactional(readOnly = true)
	public List<E> findByHql(String hql,Object[] values) throws DataAccessException{
		return getEntityDAO().findByHql(hql, values);
	}

	@Override
	public void saveOrUpdate(E entity) throws DataAccessException {
		getEntityDAO().saveOrUpdate(entity);
	}

	@Override
	public void save(E entity) throws DataAccessException {
		getEntityDAO().save(entity);
	}

	@Override
	public void removeById(PK id) throws DataAccessException {
		getEntityDAO().deleteById(id);
	}
	
	@Override
	public void removeAll(Collection c) throws DataAccessException{
		getEntityDAO().deleteAll(c);
	}

	@Override
	public void update(E entity) throws DataAccessException {
		getEntityDAO().update(entity);
	}
	
	@Override
	public Page findPage(BaseQuery query) {

		return getEntityDAO().findPage(query);
	}
}
